home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / benchmarks / write / RCS / write.c,v < prev   
Encoding:
Text File  |  1989-09-15  |  8.3 KB  |  384 lines

  1. head     1.5;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    brent:1.5; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.5
  10. date     89.09.13.20.48.26;  author ouster;  state Exp;
  11. branches ;
  12. next     1.4;
  13.  
  14. 1.4
  15. date     88.03.10.16.09.57;  author brent;  state Exp;
  16. branches ;
  17. next     1.3;
  18.  
  19. 1.3
  20. date     88.03.02.08.42.57;  author brent;  state Exp;
  21. branches ;
  22. next     1.2;
  23.  
  24. 1.2
  25. date     87.12.17.21.35.41;  author nelson;  state Exp;
  26. branches ;
  27. next     1.1;
  28.  
  29. 1.1
  30. date     87.12.17.21.24.52;  author nelson;  state Exp;
  31. branches ;
  32. next     ;
  33.  
  34.  
  35. desc
  36. @@
  37.  
  38.  
  39. 1.5
  40. log
  41. @Switchover to version that will also run under UNIX.
  42. @
  43. text
  44. @/* 
  45.  * write.c --
  46.  *
  47.  *    This program is a stand-alone benchmark to measure
  48.  *    the speed of writing a file.  It should be invoked
  49.  *    as follows:
  50.  *
  51.  *    write numK count
  52.  *
  53.  *    The program will write numK bytes to its standard
  54.  *    output, seeking back to zero and repeating count
  55.  *    times.  Then it will print out the write bandwidth.
  56.  *    If omitted, count defaults to 1.
  57.  *
  58.  * Copyright 1989 Regents of the University of California.
  59.  * Permission to use, copy, modify, and distribute this
  60.  * software and its documentation for any purpose and without
  61.  * fee is hereby granted, provided that the above copyright
  62.  * notice appear in all copies.  The University of California
  63.  * makes no representations about the suitability of this
  64.  * software for any purpose.  It is provided "as is" without
  65.  * express or implied warranty.
  66.  */
  67.  
  68. #ifndef lint
  69. static char rcsid[] = "$Header: protoPub.c,v 1.3 87/01/04 17:28:56 andrew Exp $ SPRITE (Berkeley)";
  70. #endif not lint
  71.  
  72. #include <stdio.h>
  73. #include <sys/time.h>
  74. #include <sys/resource.h>
  75.  
  76. static char buffer[16384];
  77.  
  78. main(argc, argv)
  79. int argc;
  80. char **argv;
  81. {
  82.     int total, repeats, numK, i;
  83.     double rate, micros;
  84.     struct rusage begin ,end;
  85.     struct timeval start, stop;
  86.     struct timezone tz;
  87.  
  88.     numK = atoi(argv[1]);
  89.  
  90.     if (argc == 2) {
  91.     repeats = 1;
  92.     } else {
  93.     repeats = atoi(argv[2]);
  94.     }
  95.     total = 0;
  96.  
  97. #ifdef GETRUSAGE
  98.     getrusage(RUSAGE_SELF, &begin);
  99. #else
  100.     gettimeofday(&start, (struct timezone *) NULL);
  101. #endif
  102.  
  103.     for ( ; repeats > 0; repeats--) {
  104.     lseek(1, 0, 0);
  105.     for (i = numK; i > 0; ) {
  106.         if (i > 16) {
  107.         total += write(1, buffer, 16384);
  108.         i -= 16;
  109.         } else {
  110.         total += write(1, buffer, 1024*i - 1);
  111.         i = 0;
  112.         }
  113.     }
  114.     }
  115. #ifdef GETRUSAGE
  116.     getrusage(RUSAGE_SELF, &end);
  117.     micros = (end.ru_utime.tv_sec + end.ru_stime.tv_sec
  118.         - begin.ru_utime.tv_sec - begin.ru_stime.tv_sec)*1000000
  119.         + (end.ru_utime.tv_usec - begin.ru_utime.tv_usec)
  120.         + (end.ru_stime.tv_usec - begin.ru_stime.tv_usec);
  121. #else
  122.     gettimeofday(&stop, (struct timezone *) NULL);
  123.     micros = 1000000*(stop.tv_sec - start.tv_sec)
  124.         + stop.tv_usec - start.tv_usec;
  125. #endif
  126.     rate = total/(micros/1000000.0);
  127.     fprintf(stderr, "%d bytes written at %.0f bytes/sec.\n", total, rate);
  128. }
  129. @
  130.  
  131.  
  132. 1.4
  133. log
  134. @Updated error testing suite
  135. @
  136. text
  137. @d1 31
  138. a31 24
  139. #include "sprite.h"
  140. #include "time.h"
  141. #include "fs.h"
  142. #include "io.h"
  143. #include "option.h"
  144.  
  145. static char *buffer;
  146.  
  147. int    blockSize = 16384;
  148. int    kbytes = 1024;
  149. char    *outFileName = (char *)NULL;
  150. Boolean errorTest = FALSE;
  151.  
  152. Option optionArray[] = {
  153.     {OPT_INT, 'b', (Address) &blockSize, 
  154.      "\tBlock size to use for writing (Default 16384)."},
  155.     {OPT_INT, 'k', (Address) &kbytes,
  156.      "\tKbytes to write (Default 1024)."},
  157.     {OPT_STRING, 'o', (Address)&outFileName,
  158.      "\tName of file for output (Default write.out)."},
  159.     {OPT_TRUE, 'e', (Address)&errorTest,
  160.      "\tTest error cases. "},
  161. };
  162. int numOptions = sizeof(optionArray) / sizeof(Option);
  163. d33 1
  164. a33 2
  165. int Handler();
  166. int gotSig = FALSE;
  167. d39 5
  168. a43 18
  169.     int cnt, total;
  170.     double rate, tmp;
  171.     Time before, after;
  172.     ReturnStatus status;
  173.     int    bytesToWrite;
  174.     int    outFD;
  175.     Sig_Action        newAction, oldAction;
  176.  
  177.     (void)Opt_Parse(&argc, argv, numOptions, optionArray);
  178.  
  179.     /*
  180.      * Set up signal handling, trap interrupts in order to test
  181.      * the GEN_INTERRUPTED_BY_SIGNAL return code.
  182.      */
  183.     newAction.action = SIG_HANDLE_ACTION;
  184.     newAction.handler = Handler;
  185.     newAction.sigHoldMask = 0;
  186.     Sig_SetAction(SIG_INTERRUPT, &newAction, &oldAction);
  187. d45 7
  188. a51 1
  189.     buffer = (char *)Mem_Alloc(blockSize);
  190. a52 21
  191.     bytesToWrite = kbytes * 1024;
  192.     if (outFileName == (char *)NULL) {
  193.     outFileName = "write.out";
  194.     }
  195.     status = Fs_Open(outFileName, FS_WRITE | FS_CREATE | FS_TRUNC, 0666,&outFD);
  196.     if (status != SUCCESS) {
  197.     Io_PrintStream(io_StdErr, "Could not open %s for writing, status %x\n",
  198.                outFileName, status);
  199.     Proc_Exit(status);
  200.     }
  201.     if (errorTest) {
  202.     int numErrors = 0;
  203.     Io_Print("Write Error Tests\n"); Io_Flush(io_StdOut);
  204.  
  205.     status = Fs_Write(-2, 0, 0, &cnt);
  206.     if (status == SUCCESS) {
  207.         Io_Print("ERROR: Fs_Write(-2) worked!\n");
  208.         numErrors++;
  209.     } else {
  210.         Stat_PrintMsg(status, "Fs_Write(-2)");
  211.     }
  212. d54 12
  213. a65 34
  214.     status = Fs_Write(outFD, 10, -1, &cnt);
  215.     if (status == SUCCESS) {
  216.         Io_Print("ERROR: Fs_Write{buffer = -1} worked!\n");
  217.         numErrors++;
  218.     } else {
  219.         Stat_PrintMsg(status, "Fs_Write{buffer = -1}");
  220.     }
  221.  
  222.     status = Fs_Write(outFD, -1, buffer, &cnt);
  223.     if (status == SUCCESS) {
  224.         Io_Print("ERROR: Fs_Write{count < 0} worked!\n");
  225.         numErrors++;
  226.     } else {
  227.         Stat_PrintMsg(status, "Fs_Write{count < 0}");
  228.     }
  229.  
  230.     /*
  231.      * The following case uses Fs_RawWrite because the library
  232.      * routine Fs_Write dies on a bad amountReadPtr.
  233.      */
  234.     status = Fs_RawWrite(outFD, 10, buffer, 0);
  235.     if (status == SUCCESS) {
  236.         Io_Print("ERROR: Fs_RawWrite{&cnt = 0} worked!\n");
  237.         numErrors++;
  238.     } else {
  239.         Stat_PrintMsg(status, "Fs_RawWrite{&cnt = 0}");
  240.     }
  241.  
  242.     {
  243.         int outFD2;
  244.         status = Fs_Open("/dev/null", FS_READ, 0,&outFD2);
  245.         if (status != SUCCESS) {
  246.         Io_PrintStream(io_StdErr, "Could not open %s for reading, status %x\n",
  247.                    "/dev/null", status);
  248. d67 2
  249. a68 7
  250.         status = Fs_Write(outFD2, 10, buffer, &cnt);
  251.         if (status == SUCCESS) {
  252.             Io_Print("ERROR: Fs_Write{readonly stream} worked!\n");
  253.             numErrors++;
  254.         } else {
  255.             Stat_PrintMsg(status, "Fs_Write{readonly stream}");
  256.         }
  257. d71 14
  258. a84 53
  259.  
  260.     {
  261.         char *newBuf = (char *)Mem_Alloc(100 * 1024);
  262.         Io_Print("Starting 100K write... "); Io_Flush(io_StdOut);
  263.         status = Fs_RawWrite(outFD, 100 * 1024, newBuf, &cnt);
  264.         if (gotSig) {
  265.         Io_Print("Got Signal, "); Io_Flush(io_StdOut);
  266.         }
  267.         if (status == SUCCESS) {
  268.         Io_Print("Wrote %d bytes\n", cnt);
  269.         } else {
  270.         Stat_PrintMsg(status, "write");
  271.         }
  272.     }
  273.  
  274.     Fs_Close(outFD);
  275.     status = Fs_Write(outFD, sizeof("oops"), "oops", &cnt);
  276.     if (status == SUCCESS) {
  277.         Io_Print("ERROR: Fs_Write{closed stream} worked!\n");
  278.         numErrors++;
  279.     } else {
  280.         Stat_PrintMsg(status, "Fs_Write{closed stream}");
  281.     }
  282.     if (numErrors) {
  283.         Io_Print("Write Test had %d errors\n", numErrors);
  284.     } else {
  285.         Io_Print("No errors\n");
  286.     }
  287.     Proc_Exit(numErrors);
  288.     } else {
  289.     Sys_GetTimeOfDay(&before, NULL, NULL);
  290.     while (total < bytesToWrite) {
  291.         status = Fs_Write(outFD, blockSize, buffer, &cnt);
  292.         total += cnt;
  293.         if (status != SUCCESS) {
  294.         Io_PrintStream(io_StdErr, "Write failed status %x\n", status);
  295.         Proc_Exit(status);
  296.         }
  297.     }
  298.     Fs_Close(outFD);
  299.     Sys_GetTimeOfDay(&after, NULL, NULL);
  300.     rate = after.seconds - before.seconds;
  301.     rate += (after.microseconds - before.microseconds)*.000001;
  302.     rate = total/rate;
  303.     Io_PrintStream(io_StdErr,
  304.                "%d bytes written at %.0f bytes/sec.\n", total, rate);
  305.    }
  306. }
  307.  
  308. int
  309. Handler()
  310. {
  311.     gotSig = TRUE;
  312. @
  313.  
  314.  
  315. 1.3
  316. log
  317. @Added error case testing.
  318. @
  319. text
  320. @d65 1
  321. d71 1
  322. d79 1
  323. d87 1
  324. d99 1
  325. d104 15
  326. a118 5
  327.     status = Fs_Write(0, 10, buffer, &cnt);
  328.     if (status == SUCCESS) {
  329.         Io_Print("ERROR: Fs_Write{stdIn} worked!\n");
  330.     } else {
  331.         Stat_PrintMsg(status, "Fs_Write{stdIn}");
  332. d139 1
  333. d143 6
  334. @
  335.  
  336.  
  337. 1.2
  338. log
  339. @*** empty log message ***
  340. @
  341. text
  342. @d12 1
  343. d21 2
  344. d26 3
  345. d39 1
  346. d42 10
  347. d64 8
  348. a71 7
  349.     Sys_GetTimeOfDay(&before, NULL, NULL);
  350.     while (total < bytesToWrite) {
  351.     status = Fs_Write(outFD, blockSize, buffer, &cnt);
  352.     total += cnt;
  353.     if (status != SUCCESS) {
  354.         Io_PrintStream(io_StdErr, "Write failed status %x\n", status);
  355.         Proc_Exit(status);
  356. d73 72
  357. a144 8
  358.     }
  359.     Fs_Close(outFD);
  360.     Sys_GetTimeOfDay(&after, NULL, NULL);
  361.     rate = after.seconds - before.seconds;
  362.     rate += (after.microseconds - before.microseconds)*.000001;
  363.     rate = total/rate;
  364.     Io_PrintStream(io_StdErr,
  365.                "%d bytes written at %.0f bytes/sec.\n", total, rate);
  366. d147 5
  367. @
  368.  
  369.  
  370. 1.1
  371. log
  372. @Initial revision
  373. @
  374. text
  375. @d11 1
  376. d18 2
  377. d32 1
  378. d38 9
  379. d49 1
  380. a49 1
  381.     status = Fs_Write(1, blockSize, buffer, &cnt);
  382. d56 1
  383. @
  384.